⚡ Bolt: Optimize format_security_list memory allocations - #136
Conversation
Replaced string allocations and intermediate Vecs in `format_security_list` with direct appending via `std::fmt::Write::write!` to a `&mut String` buffer. This prevents multiple heap allocations per security entry during config serialization. Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #136 +/- ##
==========================================
+ Coverage 88.51% 88.54% +0.02%
==========================================
Files 28 28
Lines 2646 2644 -2
==========================================
- Hits 2342 2341 -1
+ Misses 304 303 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
💡 What:
Updated
format_security_listinsrc/config.rsto accept a&mut Stringbuffer instead of returning a new allocatedString. Replaced intermediateVecallocations andformat!macro calls in the loop with direct buffered appending viastd::fmt::Write::write!andpush_str. Updates were made toto_formatted_stringand unit tests to pass the buffer as expected.🎯 Why:
The original implementation created a new
VecofStringcomponents (ref = ...,tag = ..., etc.) and usedparts.join(", ")inside a loop for each entry, returning a fully allocatedStringconcatenated to the root TOML buffer. This causedO(N)heap allocations when writing largevettedorcompromisedsecurity lists, introducing unnecessary overhead during configuration serialization.📊 Impact:
Significantly reduces memory allocations and CPU overhead when saving configurations with extensive vetted or compromised arrays by streaming string data directly into the final
toml_strallocation block.🔬 Measurement:
Run
cargo bench(if set up) or profile memory allocations when writing configurations containing largeSecurityEntrylists. Runcargo testto ensure serialization integrity.PR created automatically by Jules for task 5574614858700912070 started by @ffalcinelli